package 异常;

public class ExceptionDemo4 {
    public static void main(String[] args) {
        /**
         * 异常抛出的常见方法:
         * public String getMessage()  返回此 throwable 的详细消息字符串
         * public String tostring()    返回此可抛出的简短描述
         * public void printStackTrace()  把异常的错误信息输出在控制台
         */
        int arr[] = {1,2,3,4,5,6,7};
        if (arr==null){
            throw new NullPointerException();
        }
        try {
            System.out.println(arr[10]);
        } catch (ArrayIndexOutOfBoundsException e) {
            /*String message = e.getMessage();
            System.out.println(message); //Index 10 out of bounds for length 7*/

            /*String s = e.toString();
            System.out.println(s);//java.lang.ArrayIndexOutOfBoundsException: Index 10 out of bounds for length 7*/

            //常用的
            e.printStackTrace();
        }
        System.out.println("我异常后打印了");
    }
}
